package com.gzx.plugin.tjzy.modular.call.pre.mapper;

import com.gzx.plugin.tjzy.modular.call.pre.entity.GzxPreOutCallDetail;
import com.gzx.plugin.tjzy.modular.call.pre.vo.GzxPreOutCallDetailVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import vip.xiaonuo.common.mapper.BaseMapperPlus;

import java.util.List;

/**
 * @author zjt
 * @description
 * @since 2024/11/8 15:56
 */
public interface GzxPreOutCallDetailMapper extends BaseMapperPlus<GzxPreOutCallDetail, GzxPreOutCallDetailVo> {

    /**
     * 删除预测外呼子表
     */
    @Update("<script>" +
            "update gzx_pre_out_call_detail set delete_flag = 'DELETE' " +
            "where batch_number = #{batchNumber} "+
            "</script>")
    void deletePreOutCallDetail(@Param("batchNumber") String batchNumber);

    @Insert("<script>" +
            "insert into gzx_pre_out_call_detail(" +
            "batch_number, caller, liaison_name, liaison_phone, case_id,customer_info,partner_business_id," +
            "tenant_id,create_user, create_time)VALUES" +
            "<foreach collection='preOutCallDetailList' item='item' index='index' separator=','>" +
            "(#{item.batchNumber},#{item.caller},#{item.liaisonName},#{item.liaisonPhone}," +
            "#{item.caseId},#{item.customerInfo},#{item.partnerBusinessId}," +
            "#{item.tenantId},#{item.createUser},#{item.createTime})" +
            "</foreach>" +
            "</script>")
    void insertBatchDetail(List<GzxPreOutCallDetail> preOutCallDetailList);


    @Update("<script>" +
            "UPDATE gzx_pre_out_call_detail " +
            "SET " +
            "<foreach collection='preOutCallDetailList' item='item' separator=','>" +
            "call_id = CASE WHEN id = #{item.id} THEN #{item.callId} ELSE call_id END," +
            "ring_time = CASE WHEN id = #{item.id} THEN #{item.ringTime} ELSE ring_time END," +
            "call_duration = CASE WHEN id = #{item.id} THEN #{item.callDuration} ELSE call_duration END," +
            "`signal` = CASE WHEN id = #{item.id} THEN #{item.signal} ELSE `signal` END " +
            "</foreach>" +
            ",update_user = create_user,update_time = now() " +
            "WHERE id IN " +
            "<foreach collection='preOutCallDetailList' item='item' open='(' separator=',' close=')'>" +
            "#{item.id}" +
            "</foreach>" +
            "</script>")
    void updateBatchByDetailId(@Param("preOutCallDetailList") List<GzxPreOutCallDetail> preOutCallDetailList);
}
